﻿using StarsAdmin.Core.Helpers;
using System.ComponentModel.DataAnnotations;

namespace StarsAdmin.Core.Attributes
{
    public class EmailAttribute : ValidationAttribute
    {
        protected override ValidationResult? IsValid(object? value, ValidationContext validationContext)
        {
            if (value != null && !value.ToString().IsEmail())
            {
                return new ValidationResult(ErrorMessage ?? "电子邮箱地址格式不正确。");
            }

            return ValidationResult.Success;
        }
    }
}